/**
 * 
 */

package com.chengyu.eyc.config;

import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author kevin
 *
 */
@Configuration
public class EycConfig {

    @Bean
    public ServletWebServerFactory tomcatEmbedded() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        tomcat.addConnectorCustomizers((TomcatConnectorCustomizer)connector -> {
            // connector.setAttribute("relaxedQueryChars",
            // "[]|{}~`%^&#x5c;&#x60;&quot;&lt;&gt;");
            // connector.setAttribute("relaxedPathChars", "[]|");
            connector.setProperty("relaxedQueryChars", "[]|{}~`%^&#x5c;&#x60;&quot;&lt;&gt;");
            connector.setProperty("relaxedPathChars", "[]|");
            // connector other settings...
            // configure maxSwallowSize
            if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
                // -1 means unlimited, accept bytes
                ((AbstractHttp11Protocol<?>)connector.getProtocolHandler()).setMaxSwallowSize(-1);
            }
        });
        return tomcat;
    }

}
